'use strict'

let users=[
    {
        id:1,
        username:'admin',
        password:'113',
        nickname:'超级管理员',
        avatar:'这是一很帅的男人的头像'
    },
    {
        id:2,
        username:'user01',
        password:'113',
        nickname:'路人1',
        avatar:'这是一很帅的男人的头像'
    },
    {
        id:3,
        username:'user02',
        password:'113',
        nickname:'路人2',
        avatar:'这是一很帅的男人的头像'
    },
]

let fn_create = async (ctx,next)=>{
    let username = ctx.request.body.username
    let password = ctx.request.body.password

    let list = users.filter(item=>{
        return item.username === username && item.password === password
    })

    if(list.length>0){
        ctx.body={
            code : 200,
            data : list[0],
            msg : '登录成功!'
        }
    }else{
        ctx.body={
            code : 400,
            data :'',
            msg : '用户名或密码不正确!'
        }
    }
}

let fn_index = async (ctx,next)=>{
    ctx.body = '首页'
}

module.exports = {
    'post /user' : fn_create,
    'get /user' : fn_index,
    'post /login' : fn_create
}